﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.OleDb;
using System.Data;
namespace DAO
{
    public class PhieuThueDAO
    {
        public int ThemPhieuThue(PhieuThueDTO Phieu)
        {
           
            OleDbConnection cn = DataProvider.ConectDatabase();
             OleDbCommand command = new OleDbCommand("LapPhieuThue", cn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@MaPhong",Phieu.Maphong);
            command.Parameters.AddWithValue("@NgayThue", Phieu.Ngaythue);
            command.ExecuteNonQuery();
            OleDbCommand cm = new OleDbCommand("",cn);
            
            cm.CommandText = "SELECT @@IDENTITY From PhieuThuePhong";
            int i = (int)cm.ExecuteScalar();
            return i;

        }
        public DataTable LayThongTinPhieuThue(int maphieu)
        {
           
            return DataProvider.DataTableQueryParameters("LoadThongTinPhieuThue", "@MaPhieu", maphieu);
           
        }
        public int LayPhieuThueMaxTheoPhong(string maphong)
        {
            return DataProvider.getMAX("Select Max(MaPhieu) From PhieuThuePhong Where MaPhong=" + maphong);

        }
        public PhieuThueChiTietDTO GetInforChuaThanhToan(int maphong,int TinhTrang)
        {
            DataTable dt = new DataTable();
            PhieuThueChiTietDAO dao = new PhieuThueChiTietDAO();
            dt = DataProvider.DataTableQueryParameters("ThongTinPhongChuaThanhToan", "@MaPhong", maphong, "@MaTinhTrang", TinhTrang,"@ThanhToan",0);
                PhieuThueChiTietDTO dto = new PhieuThueChiTietDTO();
                dto.Maphieu = Int32.Parse(dt.Rows[0]["MaPhieu"].ToString());
               dto.Soluongkhach= dao.SoluongKhach(dto.Maphieu);
                dto.Maphong = Int32.Parse(dt.Rows[0]["MaPhong"].ToString());
            dto.Gia = Int32.Parse(dt.Rows[0]["Gia"].ToString());
                dto.Ngaythue = DateTime.Parse(dt.Rows[0]["NgayThue"].ToString());
                dto.MaloaiPhong = Int32.Parse(dt.Rows[0]["MaLoaiPhong"].ToString());
                return dto;
          

                    
        }
    }
}
